home *** CD-ROM | disk | FTP | other *** search
/ Gold Medal Software 3 / Gold Medal Software - Volume 3 (Gold Medal) (1994).iso / prog / tge131.arj / TGEDEMO.CPP < prev    next >
C/C++ Source or Header  |  1994-03-05  |  32KB  |  933 lines

  1. /**************************************************************************
  2. *  File:        TGEDEMO.CPP   Copyright (c) 1993-1994 by Matthew Hildebrand
  3. *
  4. *  Purpose:     Demonstrate TGE 1.31's features.
  5. **************************************************************************/
  6.  
  7. #include <alloc.h>
  8. #include <conio.h>
  9. #include <dos.h>
  10. #include <mem.h>
  11. #include <stdio.h>
  12. #include <stdlib.h>
  13. #include "..\include\tge.h"
  14. #include "..\include\tgemouse.h"
  15. #include "..\include\varfont.h"
  16. #include "..\include\vcoord.h"
  17.  
  18. #define TGELOGO_FILENAME    "TGELOGO.RAW"
  19. #define FONT_FILENAME       "..\\FONTS\\BIGTEXT.FNT"
  20. #define QUIT_IF_ESCAPE      if (getKey() == 27)  \
  21.                               exit(EXIT_SUCCESS)
  22.  
  23. enum
  24. {
  25.   Center, BottomCenter
  26. };
  27.  
  28. void setup(int argc, char *argv[]);
  29. void printMessage(char *string, int where=BottomCenter);
  30. void lineDemo(void);
  31. void putPixelDemo(void);
  32. void drawRectDemo(void);
  33. void filledRectDemo(void);
  34. void ellipseDemo(void);
  35. void filledEllipseDemo(void);
  36. void circleDemo(void);
  37. void filledCircleDemo(void);
  38. void putImageDemo(void);
  39. void fontDemo(void);
  40. void viewportDemo(void);
  41. void paletteDemo(void);
  42. void scaleBitmapDemo(void);
  43. void mouseDemo(void);
  44. void signOff(void);
  45. int getKey(void);
  46.  
  47. VariableFont font;
  48. void far *tgeLogo;
  49. unsigned char palette[] =
  50. {
  51.     0,   0,   0,   0,   0, 168,   0, 168,   0,   0, 168, 168,
  52.   168,   0,   0, 168,   0, 168, 168,  84,   0, 168, 168, 168,
  53.    84,  84,  84,  84,  84, 252,  84, 252,  84,  84, 252, 252,
  54.   252,  84,  84, 252,  84, 252, 252, 252,  84, 252, 252, 252,
  55.     0,   0,   0,  20,  20,  20,  32,  32,  32,  44,  44,  44,
  56.    56,  56,  56,  68,  68,  68,  80,  80,  80,  96,  96,  96,
  57.   112, 112, 112, 128, 128, 128, 144, 144, 144, 160, 160, 160,
  58.   180, 180, 180, 200, 200, 200, 224, 224, 224, 252, 252, 252,
  59.     0,   0, 252,  64,   0, 252, 124,   0, 252, 188,   0, 252,
  60.   252,   0, 252, 252,   0, 188, 252,   0, 124, 252,   0,  64,
  61.   252,   0,   0, 252,  64,   0, 252, 124,   0, 252, 188,   0,
  62.   252, 252,   0, 188, 252,   0, 124, 252,   0,  64, 252,   0,
  63.     0, 252,   0,   0, 252,  64,   0, 252, 124,   0, 252, 188,
  64.     0, 252, 252,   0, 188, 252,   0, 124, 252,   0,  64, 252,
  65.   124, 124, 252, 156, 124, 252, 188, 124, 252, 220, 124, 252,
  66.   252, 124, 252, 252, 124, 220, 252, 124, 188, 252, 124, 156,
  67.   252, 124, 124, 252, 156, 124, 252, 188, 124, 252, 220, 124,
  68.   252, 252, 124, 220, 252, 124, 188, 252, 124, 156, 252, 124,
  69.   124, 252, 124, 124, 252, 156, 124, 252, 188, 124, 252, 220,
  70.   124, 252, 252, 124, 220, 252, 124, 188, 252, 124, 156, 252,
  71.   180, 180, 252, 196, 180, 252, 216, 180, 252, 232, 180, 252,
  72.   252, 180, 252, 252, 180, 232, 252, 180, 216, 252, 180, 196,
  73.   252, 180, 180, 252, 196, 180, 252, 216, 180, 252, 232, 180,
  74.   252, 252, 180, 232, 252, 180, 216, 252, 180, 196, 252, 180,
  75.   180, 252, 180, 180, 252, 196, 180, 252, 216, 180, 252, 232,
  76.   180, 252, 252, 180, 232, 252, 180, 216, 252, 180, 196, 252,
  77.     0,   0, 112,  28,   0, 112,  56,   0, 112,  84,   0, 112,
  78.   112,   0, 112, 112,   0,  84, 112,   0,  56, 112,   0,  28,
  79.   112,   0,   0, 112,  28,   0, 112,  56,   0, 112,  84,   0,
  80.   112, 112,   0,  84, 112,   0,  56, 112,   0,  28, 112,   0,
  81.     0, 112,   0,   0, 112,  28,   0, 112,  56,   0, 112,  84,
  82.     0, 112, 112,   0,  84, 112,   0,  56, 112,   0,  28, 112,
  83.    56,  56, 112,  68,  56, 112,  84,  56, 112,  96,  56, 112,
  84.   112,  56, 112, 112,  56,  96, 112,  56,  84, 112,  56,  68,
  85.   112,  56,  56, 112,  68,  56, 112,  84,  56, 112,  96,  56,
  86.   112, 112,  56,  96, 112,  56,  84, 112,  56,  68, 112,  56,
  87.    56, 112,  56,  56, 112,  68,  56, 112,  84,  56, 112,  96,
  88.    56, 112, 112,  56,  96, 112,  56,  84, 112,  56,  68, 112,
  89.    80,  80, 112,  88,  80, 112,  96,  80, 112, 104,  80, 112,
  90.   112,  80, 112, 112,  80, 104, 112,  80,  96, 112,  80,  88,
  91.   112,  80,  80, 112,  88,  80, 112,  96,  80, 112, 104,  80,
  92.   112, 112,  80, 104, 112,  80,  96, 112,  80,  88, 112,  80,
  93.    80, 112,  80,  80, 112,  88,  80, 112,  96,  80, 112, 104,
  94.    80, 112, 112,  80, 104, 112,  80,  96, 112,  80,  88, 112,
  95.     0,   0,  64,  16,   0,  64,  32,   0,  64,  48,   0,  64,
  96.    64,   0,  64,  64,   0,  48,  64,   0,  32,  64,   0,  16,
  97.    64,   0,   0,  64,  16,   0,  64,  32,   0,  64,  48,   0,
  98.    64,  64,   0,  48,  64,   0,  32,  64,   0,  16,  64,   0,
  99.     0,  64,   0,   0,  64,  16,   0,  64,  32,   0,  64,  48,
  100.     0,  64,  64,   0,  48,  64,   0,  32,  64,   0,  16,  64,
  101.    32,  32,  64,  40,  32,  64,  48,  32,  64,  56,  32,  64,
  102.    64,  32,  64,  64,  32,  56,  64,  32,  48,  64,  32,  40,
  103.    64,  32,  32,  64,  40,  32,  64,  48,  32,  64,  56,  32,
  104.    64,  64,  32,  56,  64,  32,  48,  64,  32,  40,  64,  32,
  105.    32,  64,  32,  32,  64,  40,  32,  64,  48,  32,  64,  56,
  106.    32,  64,  64,  32,  56,  64,  32,  48,  64,  32,  40,  64,
  107.    44,  44,  64,  48,  44,  64,  52,  44,  64,  60,  44,  64,
  108.    64,  44,  64,  64,  44,  60,  64,  44,  52,  64,  44,  48,
  109.    64,  44,  44,  64,  48,  44,  64,  52,  44,  64,  60,  44,
  110.    64,  64,  44,  60,  64,  44,  52,  64,  44,  48,  64,  44,
  111.    44,  64,  44,  44,  64,  48,  44,  64,  52,  44,  64,  60,
  112.    44,  64,  64,  44,  60,  64,  44,  52,  64,  44,  48,  64,
  113.     0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,
  114.     0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0
  115. };
  116.  
  117.  
  118.  
  119. /**************************************************************************
  120. *  Function:    main
  121. *
  122. *  Purpose:     Program entry point.
  123. *
  124. *  Entry:       argc = Number of parameters - 1.
  125. *               argv = Array containing the actual parameters.
  126. *
  127. *  Exit:        N/A
  128. **************************************************************************/
  129.  
  130. void main(int argc, char *argv[])
  131. {
  132.   //*** Set things up
  133.   setup(argc, argv);
  134.  
  135.   //*** Run the demos
  136.   lineDemo();
  137.   putPixelDemo();
  138.   drawRectDemo();
  139.   filledRectDemo();
  140.   ellipseDemo();
  141.   filledEllipseDemo();
  142.   circleDemo();
  143.   filledCircleDemo();
  144.   putImageDemo();
  145.   fontDemo();
  146.   viewportDemo();
  147.   paletteDemo();
  148.   scaleBitmapDemo();
  149.   mouseDemo();
  150.  
  151.   //*** Get a key before quitting
  152.   getKey();
  153. }
  154.  
  155.  
  156.  
  157. /**************************************************************************
  158. *  Function:    setup
  159. *
  160. *  Purpose:     Load drivers and fonts, and do other setup things.
  161. *
  162. *  Entry:       argc = Number of parameters - 1.
  163. *               argv = Array containing the actual parameters.
  164. *
  165. *  Exit:        If an error occurs, the program will exit from within this
  166. *               function.
  167. **************************************************************************/
  168.  
  169. void setup(int argc, char *argv[])
  170. {
  171.   //*** Parse command line
  172.   if (argc != 2)
  173.   {
  174.     printf("TGEDEMO 1.31  Copyright (c) 1993-1994 by Matthew Hildebrand\n\n"
  175.            "        Usage:  TGEDEMO driver[.drv]\n\n"
  176.            "     Examples:  tgedemo 320x200\n"
  177.            "                tgedemo ..\\drivers\\640x480.drv\n"
  178.            "                tgedemo d:\\tge\\drivers\\360x480\n\n");
  179.     exit(EXIT_FAILURE);
  180.   }
  181.   clrscr();                                 // clear the screen
  182.  
  183.   //*** Load the specified graphics driver
  184.   switch (loadGraphDriver(argv[1]))
  185.   {
  186.     case TGE_SUCCESS:                       // success
  187.       break;
  188.     case TGE_OPEN_ERR:                      // file not found
  189.       printf("Error opening driver file %s; aborting.\n\n"
  190.              "Please ensure that the file specified is spelled correctly, and that the\n"
  191.              "TGEDRIVERS environment variable has been set to point to the TGE drivers\n"
  192.              "directory; refer to TGEDEMO.DOC for more information.\n\n",
  193.              argv[1]);
  194.       exit(EXIT_FAILURE);
  195.     case TGE_FORMAT_ERR:                    // not a TGE driver
  196.       printf("Format error processing file %s; aborting.\n\n", argv[1]);
  197.       exit(EXIT_FAILURE);
  198.     case TGE_ALLOC_ERR:                     // out of memory
  199.       printf("Insufficient memory; aborting.\n\n");
  200.       exit(EXIT_FAILURE);
  201.     case TGE_FILE_ERR:                      // file read error
  202.       printf("Error reading file %s; aborting.\n\n", argv[1]);
  203.       exit(EXIT_FAILURE);
  204.     default:                                // who knows?
  205.       printf("Unknown error loading driver %s; aborting.\n\n", argv[1]);
  206.       exit(EXIT_FAILURE);
  207.   }
  208.   atexit(unloadGraphDriver);                // unload driver on exit
  209.  
  210.   //*** Load the TGE logo bitmap
  211.   tgeLogo = loadRawFile(TGELOGO_FILENAME);  // load it
  212.   if (tgeLogo == NULL)                      // check for errors
  213.   {
  214.     printf("Error loading bitmap file %s; aborting.\n\n", TGELOGO_FILENAME);
  215.     exit(EXIT_FAILURE);
  216.   }
  217.  
  218.   //*** Switch to graphics mode
  219.   if (!initGraphics())                      // initialize graphics mode
  220.   {
  221.     printf("Unable to initialize graphics hardware; aborting.\n\n"
  222.            "Try installing the Universal VESA TSR before running this\n"
  223.            "program again; refer to UNIVESA.DOC for more information.\n\n");
  224.     exit(EXIT_FAILURE);
  225.   }
  226.   setBlockPalette(0, 255, palette);         // set the palette
  227.  
  228.   //*** Load the font
  229.   if (font.load(FONT_FILENAME) == 0)
  230.   {
  231.     deInitGraphics();
  232.     printf("Error loading font file %s; aborting.\n\n"
  233.            "Please ensure that the file specified is spelled correctly, and that the\n"
  234.            "TGEFONTS environment variable has been set to point to the TGE fonts\n"
  235.            "directory; refer to TGEDEMO.DOC for more information.\n\n",
  236.            FONT_FILENAME);
  237.     exit(EXIT_FAILURE);
  238.   }
  239.  
  240.   //*** Seed the random number generator
  241.   randomize();
  242.  
  243.   //*** Sign off before exit
  244.   atexit(signOff);                          // display sign-off message
  245.   atexit(deInitGraphics);                   // restore text mode
  246. }
  247.  
  248.  
  249.  
  250. /**************************************************************************
  251. *  Function:    printMessage
  252. *
  253. *  Purpose:     Print a one-line message centered on the screen.
  254. *
  255. *  Entry:       string = Message to display
  256. *               where = Flag indicating where to display message.  Can be
  257. *                       Center or BottomCenter.
  258. *
  259. *  Exit:        N/A
  260. **************************************************************************/
  261.  
  262. void printMessage(char *string, int where)
  263. {
  264.   switch (where)
  265.   {
  266.     case Center:
  267.       font.put(((OUTVIEWPORTLRX-OUTVIEWPORTULX+1-font.width(string)) / 2),
  268.               ((OUTVIEWPORTLRY-OUTVIEWPORTULY+1-font.maxHeight()) / 2),
  269.                string);
  270.       break;
  271.     case BottomCenter:
  272.       font.put(((OUTVIEWPORTLRX-OUTVIEWPORTULX+1-font.width(string)) / 2),
  273.                OUTVIEWPORTLRY-font.maxHeight(),
  274.                string);
  275.       break;
  276.     default:
  277.       ;
  278.   }
  279. }
  280.  
  281.  
  282.  
  283. /**************************************************************************
  284. *  Function:    lineDemo
  285. *
  286. *  Purpose:     Demonstrate line().
  287. *
  288. *  Entry:       N/A
  289. *
  290. *  Exit:        N/A
  291. **************************************************************************/
  292.  
  293. void lineDemo(void)
  294. {
  295.   static char message[] = "TGE can draw lines...";
  296.   int maxY, count;
  297.  
  298.   //*** Set up the message
  299.   printMessage(message);                    // print it
  300.   maxY = OUTMAXY - font.maxHeight() - 4;    // get usable limits
  301.  
  302.   //*** Draw lines until a key is struck
  303.   while (!kbhit())
  304.   {
  305.     for (count=0; count<100; count++)
  306.       line(random(OUTMAXX+1), random(maxY),
  307.            random(OUTMAXX+1), random(maxY),
  308.            random(MAXCOLOUR+1));
  309.   }
  310.   QUIT_IF_ESCAPE;                           // quit if ESC pressed
  311. }
  312.  
  313.  
  314.  
  315. /**************************************************************************
  316. *  Function:    putPixelDemo
  317. *
  318. *  Purpose:     Demonstrate putPixel().
  319. *
  320. *  Entry:       N/A
  321. *
  322. *  Exit:        N/A
  323. **************************************************************************/
  324.  
  325. void putPixelDemo(void)
  326. {
  327.   static char message[] = "pixels...";
  328.   int maxY, count;
  329.  
  330.   //*** Set up the message
  331.   clearGraphics(0);                         // clear screen to black
  332.   printMessage(message);                    // print it
  333.   maxY = OUTMAXY - font.maxHeight() - 4;    // get usable limits
  334.  
  335.   //*** Draw pixels until a key is struck
  336.   while (!kbhit())
  337.   {
  338.     for (count=0; count<2000; count++)
  339.       putPixel(random(OUTMAXX+1), random(maxY), random(MAXCOLOUR+1));
  340.   }
  341.   QUIT_IF_ESCAPE;                           // quit if ESC pressed
  342. }
  343.  
  344.  
  345.  
  346. /**************************************************************************
  347. *  Function:    drawRectDemo
  348. *
  349. *  Purpose:     Demonstrate drawRect().
  350. *
  351. *  Entry:       N/A
  352. *
  353. *  Exit:        N/A
  354. **************************************************************************/
  355.  
  356. void drawRectDemo(void)
  357. {
  358.   static char message[] = "rectangles...";
  359.   int maxY, count;
  360.  
  361.   //*** Set up the message
  362.   clearGraphics(0);                         // clear screen to black
  363.   printMessage(message);                    // print it
  364.   maxY = OUTMAXY - font.maxHeight() - 4;    // get usable limits
  365.  
  366.   //*** Draw rectangles until a key is struck
  367.   while (!kbhit())
  368.   {
  369.     for (count=0; count<100; count++)
  370.       drawRect(random(OUTMAXX+1), random(maxY),
  371.                random(OUTMAXX+1), random(maxY),
  372.                random(MAXCOLOUR+1));
  373.   }
  374.   QUIT_IF_ESCAPE;                           // quit if ESC pressed
  375. }
  376.  
  377.  
  378.  
  379. /**************************************************************************
  380. *  Function:    filledRectDemo
  381. *
  382. *  Purpose:     Demonstrate filledRectDemo().
  383. *
  384. *  Entry:       N/A
  385. *
  386. *  Exit:        N/A
  387. **************************************************************************/
  388.  
  389. void filledRectDemo(void)
  390. {
  391.   static char message[] = "filled rectangles...";
  392.   int maxY, count;
  393.  
  394.   //*** Set up the message
  395.   clearGraphics(0);                         // clear screen to black
  396.   printMessage(message);                    // print it
  397.   maxY = OUTMAXY - font.maxHeight() - 4;    // get usable limits
  398.  
  399.   //*** Draw filled rectangles until a key is struck
  400.   while (!kbhit())
  401.   {
  402.     for (count=0; count<50; count++)
  403.       filledRect(random(OUTMAXX+1), random(maxY),
  404.                  random(OUTMAXX+1), random(maxY),
  405.                  random(MAXCOLOUR+1));
  406.   }
  407.   QUIT_IF_ESCAPE;                           // quit if ESC pressed
  408. }
  409.  
  410.  
  411.  
  412. /**************************************************************************
  413. *  Function:    ellipseDemo
  414. *
  415. *  Purpose:     Demonstrate ellipse().
  416. *
  417. *  Entry:       N/A
  418. *
  419. *  Exit:        N/A
  420. **************************************************************************/
  421.  
  422. void ellipseDemo(void)
  423. {
  424.   static char message[] = "ellipses...";
  425.   int maxY, count;
  426.  
  427.   //*** Set up the message
  428.   clearGraphics(0);                         // clear screen to black
  429.   printMessage(message);                    // print it
  430.   maxY = OUTMAXY - font.maxHeight() - 4;    // get usable limits
  431.  
  432.   //*** Draw ellipses until a key is struck
  433.   setOutputViewport(0, 0, SCREENMAXX, maxY);  // set the viewport
  434.   while (!kbhit())
  435.   {
  436.     for (count=0; count<100; count++)
  437.       ellipse(random(OUTMAXX+1), random(OUTMAXY+1),
  438.               random((OUTMAXX+1)/8)*2+10, random((OUTMAXY+1)/8)*2+10,
  439.               random(MAXCOLOUR+1));
  440.   }
  441.   QUIT_IF_ESCAPE;                           // quit if ESC pressed
  442.   setOutputViewport(0, 0, SCREENMAXX, SCREENMAXY);  // reset viewport
  443. }
  444.  
  445.  
  446.  
  447. /**************************************************************************
  448. *  Function:    filledEllipseDemo
  449. *
  450. *  Purpose:     Demonstrate filledEllipse().
  451. *
  452. *  Entry:       N/A
  453. *
  454. *  Exit:        N/A
  455. **************************************************************************/
  456.  
  457. void filledEllipseDemo(void)
  458. {
  459.   static char message[] = "filled ellipses...";
  460.   int maxY, count;
  461.  
  462.   //*** Set up the message
  463.   clearGraphics(0);                         // clear screen to black
  464.   printMessage(message);                    // print it
  465.   maxY = OUTMAXY - font.maxHeight() - 4;    // get usable limits
  466.  
  467.   //*** Draw filled ellipses until a key is struck
  468.   setOutputViewport(0, 0, SCREENMAXX, maxY);  // set the viewport
  469.   while (!kbhit())
  470.   {
  471.     for (count=0; count<30; count++)
  472.       filledEllipse(random(OUTMAXX+1), random(OUTMAXY+1),
  473.                     random((OUTMAXX+1)/8)*2+10, random((OUTMAXY+1)/8)*2+10,
  474.                     random(MAXCOLOUR+1));
  475.   }
  476.   QUIT_IF_ESCAPE;                           // quit if ESC pressed
  477.   setOutputViewport(0, 0, SCREENMAXX, SCREENMAXY);  // reset viewport
  478. }
  479.  
  480.  
  481.  
  482. /**************************************************************************
  483. *  Function:    circleDemo
  484. *
  485. *  Purpose:     Demonstrate circle().
  486. *
  487. *  Entry:       N/A
  488. *
  489. *  Exit:        N/A
  490. **************************************************************************/
  491.  
  492. void circleDemo(void)
  493. {
  494.   static char message[] = "circles...";
  495.   int maxY, count;
  496.  
  497.   //*** Set up the message
  498.   clearGraphics(0);                         // clear screen to black
  499.   printMessage(message);                    // print it
  500.   maxY = OUTMAXY - font.maxHeight() - 4;    // get usable limits
  501.  
  502.   //*** Draw circles until a key is struck
  503.   setOutputViewport(0, 0, SCREENMAXX, maxY);  // set the viewport
  504.   while (!kbhit())
  505.   {
  506.     for (count=0; count<100; count++)
  507.       circle(random(OUTMAXX+1), random(OUTMAXY+1),
  508.              random((OUTMAXX+1)/8)+10,
  509.              random(MAXCOLOUR+1));
  510.   }
  511.   QUIT_IF_ESCAPE;                           // quit if ESC pressed
  512.   setOutputViewport(0, 0, SCREENMAXX, SCREENMAXY);  // reset viewport
  513. }
  514.  
  515.  
  516.  
  517. /**************************************************************************
  518. *  Function:    filledCircleDemo
  519. *
  520. *  Purpose:     Demonstrate filledCircle().
  521. *
  522. *  Entry:       N/A
  523. *
  524. *  Exit:        N/A
  525. **************************************************************************/
  526.  
  527. void filledCircleDemo(void)
  528. {
  529.   static char message[] = "filled circles...";
  530.   int maxY, count;
  531.  
  532.   //*** Set up the message
  533.   clearGraphics(0);                         // clear screen to black
  534.   printMessage(message);                    // print it
  535.   maxY = OUTMAXY - font.maxHeight() - 4;    // get usable limits
  536.  
  537.   //*** Draw filled circles until a key is struck
  538.   setOutputViewport(0, 0, SCREENMAXX, maxY);  // set the viewport
  539.   while (!kbhit())
  540.   {
  541.     for (count=0; count<30; count++)
  542.       filledCircle(random(OUTMAXX+1), random(OUTMAXY+1),
  543.                    random((OUTMAXX+1)/8)+10,
  544.                    random(MAXCOLOUR+1));
  545.   }
  546.   QUIT_IF_ESCAPE;                           // quit if ESC pressed
  547.   setOutputViewport(0, 0, SCREENMAXX, SCREENMAXY);  // reset viewport
  548. }
  549.  
  550.  
  551.  
  552. /**************************************************************************
  553. *  Function:    putImageDemo
  554. *
  555. *  Purpose:     Demonstrate putImage().
  556. *
  557. *  Entry:       N/A
  558. *
  559. *  Exit:        N/A
  560. **************************************************************************/
  561.  
  562. void putImageDemo(void)
  563. {
  564.   static char message[] = "images...";
  565.   int maxY, curX, curY;
  566.  
  567.   //*** Set up the message
  568.   clearGraphics(0);                         // clear screen to black
  569.   printMessage(message);                    // print it
  570.   maxY = OUTMAXY - font.maxHeight() - 4;    // get usable limits
  571.  
  572.   //*** Set the viewport to exclude the message area
  573.   setOutputViewport(0, 0, SCREENMAXX, maxY);
  574.  
  575.   //*** Draw the TGE logo all over the background
  576.   curY = -(((maxY+1)%imageHeight(tgeLogo)) / 2);    // starting y-coordinate
  577.   curX = -(((OUTMAXX+1)%imageWidth(tgeLogo)) / 2);  // starting x-coordinate
  578.   do
  579.   {
  580.     do
  581.     {
  582.       putImage(curX, curY, tgeLogo);        // draw the logo
  583.       curX += imageWidth(tgeLogo);          // update x-coordinate
  584.     }
  585.     while (curX <= OUTMAXX);
  586.     curY += imageHeight(tgeLogo);           // update y-coordinate
  587.     curX = -(((OUTMAXX+1)%imageWidth(tgeLogo)) / 2);  // starting x-coordinate
  588.   }
  589.   while (curY <= maxY);
  590.   QUIT_IF_ESCAPE;                           // quit if ESC pressed
  591.  
  592.   //*** Reset the viewport to cover the whole screen
  593.   setOutputViewport(0, 0, SCREENMAXX, SCREENMAXY);
  594. }
  595.  
  596.  
  597.  
  598. /**************************************************************************
  599. *  Function:    fontDemo
  600. *
  601. *  Purpose:     Demonstrate fonts.
  602. *
  603. *  Entry:       N/A
  604. *
  605. *  Exit:        N/A
  606. **************************************************************************/
  607.  
  608. void fontDemo(void)
  609. {
  610.   static char message[] = "and, of course, text.";
  611.  
  612.   //*** Set up the message
  613.   clearGraphics(0);                         // clear screen to black
  614.   printMessage(message, Center);            // print it
  615.   QUIT_IF_ESCAPE;                           // quit if ESC pressed
  616. }
  617.  
  618.  
  619.  
  620. /**************************************************************************
  621. *  Function:    viewportDemo
  622. *
  623. *  Purpose:     Demonstrate viewports.
  624. *
  625. *  Entry:       N/A
  626. *
  627. *  Exit:        N/A
  628. **************************************************************************/
  629.  
  630. void viewportDemo(void)
  631. {
  632.   static char message[] = "Output can be clipped.";
  633.   VirtualCoord virtScreen;
  634.   int x1, y1, x2, y2;
  635.  
  636.   //*** Set up the message
  637.   font.palette(1, 255, 255, 255);           // update font colour
  638.   clearGraphics(colourCloseTo(90,90,90));   // clear screen to black
  639.   printMessage(message);                    // print it
  640.  
  641.   //*** Configure the virtual coordinate system
  642.   virtScreen.virtParams(4, 4);
  643.   virtScreen.realParams(OUTMAXX, OUTMAXY);
  644.  
  645.   //*** Set the viewport to exclude the message area
  646.   x1 = virtScreen.realX(1);
  647.   y1 = virtScreen.realY(1);
  648.   x2 = virtScreen.realX(3);
  649.   y2 = virtScreen.realY(3);
  650.   setOutputViewport(x1, y1, x2, y2);
  651.   filledRect(x1, y1, x2, y2, colourCloseTo(0,0,0));
  652.  
  653.   //*** Draw random things at random places.
  654.   while (!kbhit())
  655.   {
  656.     switch (random(8))                      // choose a thing to draw
  657.     {
  658.       case 0:                               // line()
  659.     x1 = random(OUTMAXX+1);
  660.     y1 = random(OUTMAXY+1);
  661.     x2 = random(OUTMAXX+1);
  662.     y2 = random(OUTMAXY+1);
  663.     if (clipLine(&x1, &y1, &x2, &y2))
  664.           line(x1, y1, x2, y2, random(MAXCOLOUR+1));
  665.     break;
  666.       case 1:                               // ellipse()
  667.         ellipse(random(OUTMAXX+1), random(OUTMAXY+1),
  668.                 random(OUTMAXX/3), random(OUTMAXY/3),
  669.                 random(MAXCOLOUR+1));
  670.     break;
  671.       case 2:                               // filledEllipse();
  672.         filledEllipse(random(OUTMAXX+1), random(OUTMAXY+1),
  673.                       random(OUTMAXX/3), random(OUTMAXY/3),
  674.                       random(MAXCOLOUR+1));
  675.     break;
  676.       case 3:                               // circle()
  677.     circle(random(OUTMAXX+1), random(OUTMAXY+1), random(OUTMAXX/3),
  678.                 random(MAXCOLOUR+1));
  679.     break;
  680.       case 4:                               // filledCircle()
  681.     filledCircle(random(OUTMAXX+1), random(OUTMAXY+1), random(OUTMAXX/3),
  682.                 random(MAXCOLOUR+1));
  683.     break;
  684.       case 5:                               // putImageInv()
  685.     putImageInv(random(OUTMAXX+1), random(OUTMAXY+1), tgeLogo);
  686.     break;
  687.       case 6:                               // filledRect()
  688.     x1 = random(OUTMAXX+1);
  689.     y1 = random(OUTMAXY+1);
  690.     x2 = random(OUTMAXX+1);
  691.     y2 = random(OUTMAXY+1);
  692.     if (clipFilledRect(&x1, &y1, &x2, &y2))
  693.           filledRect(x1, y1, x2, y2, random(MAXCOLOUR+1));
  694.     break;
  695.       case 7:
  696.     drawRect(random(OUTMAXX+1), random(OUTMAXY+1), random(OUTMAXX+1),
  697.                 random(OUTMAXY+1), random(MAXCOLOUR+1));
  698.     break;
  699.       default:
  700.     ;
  701.     }
  702.   }
  703.   QUIT_IF_ESCAPE;                           // quit if ESC pressed
  704.  
  705.   //*** Reset the viewport to cover the whole screen
  706.   setOutputViewport(0, 0, SCREENMAXX, SCREENMAXY);
  707. }
  708.  
  709.  
  710.  
  711. /**************************************************************************
  712. *  Function:    paletteDemo
  713. *
  714. *  Purpose:     Demonstrate palette fading and rotation.
  715. *
  716. *  Entry:       N/A
  717. *
  718. *  Exit:        N/A
  719. **************************************************************************/
  720.  
  721. void paletteDemo(void)
  722. {
  723.   static char message[] = "TGE has other powerful features...";
  724.   unsigned char inPal[768], outPal[768], targetPalA[768], targetPalB[768];
  725.   void *in, *out, *temp;
  726.   int count, stillFadingFlag=1;
  727.  
  728.   //*** Introduce the next two demos
  729.   clearGraphics(0);                         // clear screen to black
  730.   printMessage(message, Center);            // print it
  731.   QUIT_IF_ESCAPE;                           // quit if ESC pressed
  732.  
  733.   //*** Initialize the palettes
  734.   memcpy(targetPalA, palette, 768);         // copy target palette into buffer
  735.   memset(inPal, 0x00, 768);                 // black starting palette
  736.   setBlockPalette(0, 255, inPal);           // set palette to black
  737.  
  738.   //*** Fill the screen with horizontal lines
  739.   for (count=0; count<=OUTMAXY; count++)
  740.     horizLine(count, 0, OUTMAXX, count&0xFF);
  741.  
  742.   //*** Rotate the palette until a key is pressed
  743.   in = (void*) inPal;                       // point to input buffer
  744.   out = (void*) outPal;                     // point to output buffer
  745.   while (!kbhit())
  746.   {
  747.     if (stillFadingFlag)                    // fade the palette in
  748.     {
  749.       stillFadingFlag = fadePalette(1, in, out, (void*)targetPalA);
  750.       memcpy(in, out, 768);
  751.     }
  752.     delay(10);                              // delay for a bit
  753.     rotatePalette(1, in, out);              // rotate the palette
  754.     rotatePalette(1, targetPalA, targetPalB); // rotate target palette
  755.     memcpy(targetPalA, targetPalB, 768);    // update target palette
  756.     setBlockPalette(0, 255, out);           // update the palette
  757.     temp = out;                             // swap input and output pointers
  758.     out = in;
  759.     in = temp;
  760.   }
  761.  
  762.   QUIT_IF_ESCAPE;                           // quit if ESC pressed
  763.   setBlockPalette(0, 255, palette);         // restore palette
  764. }
  765.  
  766.  
  767.  
  768. /**************************************************************************
  769. *  Function:    scaleBitmapDemo
  770. *
  771. *  Purpose:     Demonstrate scaleBitmap.
  772. *
  773. *  Entry:       N/A
  774. *
  775. *  Exit:        N/A
  776. **************************************************************************/
  777.  
  778. void scaleBitmapDemo(void)
  779. {
  780.   void far *image;
  781.   unsigned count;
  782.  
  783.   //*** Grab a block of memory
  784.   if ((image=farmalloc(imageSizeDim(200,200))) == NULL)
  785.   {
  786.     deInitGraphics();
  787.     printf("Insufficient memory; aborting.\n\n"
  788.            "Press a key to continue...");
  789.     getKey();
  790.     clrscr();
  791.     exit(EXIT_FAILURE);
  792.   }
  793.  
  794.   //*** Make image grow from center of screen
  795.   clearGraphics(0);                         // clear screen to black
  796.   for (count=1; count<=200&&!kbhit(); count++)
  797.   {
  798.     scaleBitmap(tgeLogo, count, count, image);       // scale it
  799.     putImage((MAXX+1-count)/2, (MAXY+1-count)/2, image); // draw it
  800.   }
  801.  
  802.   //*** Clean up and go home
  803.   farfree(image);                           // release memory
  804.   if (kbhit())                              // if a key was pressed, then
  805.     QUIT_IF_ESCAPE;                         // quit if ESC pressed
  806. }
  807.  
  808.  
  809.  
  810. /**************************************************************************
  811. *  Function:    mouseDemo
  812. *
  813. *  Purpose:     Demonstrate the use of the mouse.
  814. *
  815. *  Entry:       N/A
  816. *
  817. *  Exit:        N/A
  818. **************************************************************************/
  819.  
  820. void mouseDemo(void)
  821. {
  822.   int pointerNum;
  823.  
  824.   //*** Ensure that a mouse is installed
  825.   if (!resetMouse())
  826.   {
  827.     deInitGraphics();
  828.     printf("Microsoft or compatible mouse not detected.\n"
  829.        "The demo for definable, device-independent pointers will not be run.\n\n"
  830.        "Press a key to continue...");
  831.     getKey();
  832.     clrscr();
  833.     exit(EXIT_SUCCESS);
  834.   }
  835.  
  836.   //*** Initialize the mouse handler
  837.   initNewMouse();                           // initialize handler
  838.   setHorizLimitsMouse(0, OUTMAXX);          // set horizontal limits
  839.   setVertLimitsMouse(0, OUTMAXY);           // set vertical limits
  840.   setPosMouse(OUTMAXX/2, OUTMAXY/2);        // center pointer on-screen
  841.   pointerNum = BIG_ARROW_POINTER;           // signal using BIG_ARROW_POINTER
  842.   setupMousePointer(pointerNum);            // make BIG_ARROW_POINTER active
  843.   showMouse();                              // show the pointer
  844.  
  845.   //*** Main loop
  846.   while (!kbhit())
  847.   {
  848.     //*** Button pressed; change to BIG_TARGET_POINTER
  849.     if (buttonMouse() && pointerNum!=BIG_TARGET_POINTER)
  850.     {
  851.       pointerNum = BIG_TARGET_POINTER;      // signal using BIG_TARGET_POINTER
  852.       setupMousePointer(pointerNum);        // make BIG_TARGET_POINTER active
  853.     }
  854.     //*** Button released; change to BIG_ARROW_POINTER
  855.     else if (!buttonMouse() && pointerNum==BIG_TARGET_POINTER)
  856.     {
  857.       pointerNum = BIG_ARROW_POINTER;       // signal using BIG_ARROW_POINTER
  858.       setupMousePointer(pointerNum);        // make BIG_ARROW_POINTER active
  859.     }
  860.   }
  861.  
  862.   //*** Shut off mouse handler
  863.   deInitNewMouse();
  864. }
  865.  
  866.  
  867.  
  868. /**************************************************************************
  869. *  Function:    signOff
  870. *
  871. *  Purpose:     Print a sign-off message.
  872. *
  873. *  Entry:       N/A
  874. *
  875. *  Exit:        N/A
  876. **************************************************************************/
  877.  
  878. void signOff(void)
  879. {
  880.   static char notice[] =
  881.   {
  882.     "┌──────────────────────────────────────────────────────────────────────────────┐"
  883.     "│ The Graphics Engine 1.31 Demo  Copyright (c) 1993-1994 by Matthew Hildebrand │"
  884.     "╞══════════════════════════════════════════════════════════════════════════════╡"
  885.     "│ Although this program is not particularly gripping, it demonstrates TGE's    │"
  886.     "│ speed and most of its many features.  TGE is especially suited to device-    │"
  887.     "│ independence, as can be seen by running this demo with different drivers,    │"
  888.     "│ though it may of course be used in single-mode programs as well.             │"
  889.     "│                                                                              │"
  890.     "│ TGE has many features, including:                                            │"
  891.     "│      ■ Use of loadable graphics drivers and loadable fonts                   │"
  892.     "│      ■ A powerful set of graphical functions                                 │"
  893.     "│      ■ Support for viewports, or clipping regions                            │"
  894.     "│      ■ Support for virtual screens of varying sizes                          │"
  895.     "│      ■ Extensive mouse support, including definable pointers                 │"
  896.     "│      ■ Graphics output using COPY, AND, NOT, OR, and XOR                     │"
  897.     "│      ■ Native support for both PCX files and TGE-format RAW files            │"
  898.     "│                                                                              │"
  899.     "│ TGE costs a mere $30 US funds or $40 Canadian funds; paid users are entitled │"
  900.     "│ to free upgrades, technical support, royalty-free distribution rights,       │"
  901.     "│ complete source code, and eternal happiness.  Refer to TGE.DOC for details.  │"
  902.     "╞══════════════════════════════════════════════════════════════════════════════╡"
  903.     "│ Matthew Hildebrand, 4 College St., St. Catharines, Ontario, Canada, L2R 2W7  │"
  904.     "└──────────────────────────────────────────────────────────────────────────────┘"
  905.   };
  906.  
  907.   printf(notice);                           // print the message
  908. }
  909.  
  910.  
  911.  
  912. /**************************************************************************
  913. *  Function:    getKey
  914. *
  915. *  Purpose:     Get a character from the keyboard.  This function differs
  916. *               from getch() in that it can correctly handle extended keys
  917. *               such as the function keys.
  918. *
  919. *  Entry:       N/A
  920. *
  921. *  Exit:        Returns the keycode of the key pressed.
  922. **************************************************************************/
  923.  
  924. int getKey(void)
  925. {
  926.   int ch;
  927.  
  928.   ch = getch();                             // get a byte
  929.   if (!(ch & 0xFF))                         // is it zero?
  930.     ch = getch() << 8;                      // yes, get another byte
  931.   return (ch);                              // return the keycode
  932. }
  933.